<template>
    <div class="newsinfo-container">
        <!-- 标题 -->
        <h3 class="title">{{newinfo.title}}</h3>
        <!-- 小标题 -->
        <p class="subtitle">
            <span>发表时间：{{ newinfo.add_time | dateFormat}}</span>
            <span>点击：{{ newinfo.click }}次</span>
        </p>
        <hr>
        <!-- 内容 -->
        <div class="content" v-html="newinfo.content"></div>
        <!-- 评论 -->
        <comment-box :id="this.id"></comment-box>
    </div>
</template>
<script>
import { Toast } from 'mint-ui'

import comment from '../subcomponents/comment.vue'

    export default{
        data() {
            return {
                id : this.$route.params.id,   //将url传递的id值挂载到vm上，方便调用
                newinfo : {}
            }
        },
        created() {
            this.getnewsinfo();
        },
        methods: {
            getnewsinfo(){
                this.$http.get('api/getnew/'+this.id).then(result => {
                    if(result.body.status ===0){
                        this.newinfo = result.body.message[0]
                    }else{
                        Toast('新闻信息出错')
                    }
                })
            }
        },
        components:{
            'comment-box':comment
        }
    }
</script>


<style lang="scss"> // 如果内容中有图片则需要将scoped这个属性去掉
    .newsinfo-container{
        padding: 0 4px;

        .title{
            font-size: 16px;
            text-align: center;
            margin: 15px 0;
            color: red;
        }

        .subtitle{
            font-size: 12px;
            color: #222fff;
            display: flex;
            justify-content: space-between;
        }

        .content{
            width: 100%;
        }
    }
</style>